/*
 * Copyright (c)$today.year.month.day
 *  admin:郑程荣.
 *  文件名:LoginPresenter.java
 *  项目功能:
 */

package com.jg.myproject.presenter;

import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jg.myproject.api.Const;
import com.jg.myproject.api.RetrofitFactory;
import com.jg.myproject.api.RxSchedulers;
import com.jg.myproject.api.bean.CommonRequestBean;
import com.jg.myproject.api.bean.UserBean;
import com.jg.myproject.api.bean.reponse.CommonReponseBean;
import com.jg.myproject.module.base.IBasePresenter;
import com.jg.myproject.api.BaseObserver;
import com.jg.myproject.api.bean.BaseEntity;
import com.jg.myproject.pview.ILoginView;
import com.vondear.rxtools.view.RxToast;

import java.util.ArrayList;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;


public class LoginPresenter implements IBasePresenter<UserBean> {

   private ILoginView mLoginView;
    public LoginPresenter(ILoginView loginView){
        this.mLoginView = loginView;
    }
    @Override
    public void getData(UserBean userBean) {
        // 登陆
        Observable<BaseEntity<CommonReponseBean>> observable = RetrofitFactory.getInstance().toLogin(userBean);
         observable.compose(RxSchedulers.<BaseEntity<CommonReponseBean>>compose(mLoginView.<BaseEntity<CommonReponseBean>>bindToLife()
        )).subscribe(new BaseObserver<CommonReponseBean>(mLoginView) {
            @Override
            protected void onHandleSuccess(BaseEntity<CommonReponseBean> bean) {
                if(bean.getBeans()!=null &&bean.getBeans().size()>0) {
                    mLoginView.getReponseBeans(bean);
                }
            }
            @Override
            protected void onHandleError(BaseEntity<CommonReponseBean> bean) {
                RxToast.showToast(bean.getMessage());
            }
        });
    }
}
